<template>
<div>
  <head title="Selling"></head>
  <scroller class="scroller">
    <div v-for="(list, index) in orderList" :key="index" class="sellItem">
      <div class="sellItem-con bb">
        <image class="imgList" :src="list.thumb" />
        <div class="bottomList">
          <text class="sellItem-tit">{{list.title}}</text>
          <text class="sellItem-mon">AU${{list.price}}</text>
        </div>
      </div>
      <div class="sellItem-act">
        <text class="actionItem" @click="push('root:app/goods/goods2.js',{id:list.id})">Detail</text>
        <!-- <text class="actionItem">Polish</text> -->
        <text class="actionItem" @click="revoke(list.id)">Remove</text>
        <text class="actionItem" @click="push('root:app/selling/selling.js',{id:list.id})">Edit</text>
      </div>
    </div>
    <div v-if="orderList.length==0&&!isLoading">
      <empty tips="Your Selling is empty"></empty>
      <text class="sellBtn" @click="push('root:app/selling/selling.js')">Sell an item</text>
    </div>
  </scroller>

  <div class="maskClack" @click="e=>e.stopPropagation()" v-if="isLoading">
    <floading class="indicator" color="#333333"></floading>
  </div>
</div>
</template>
<script>
import asCore from "../../mixin/core";
const editSell = new BroadcastChannel("editSell");
import { get_goods_list, lower_twohand_goods } from "../../mixin/ajax";
export default {
  data() {
    return {
      orderList: [],
      users_id: "",
      page: 1
    };
  },
  created() {
    let that = this;
    editSell.onmessage = function() {
      that.getList();
    };
    asCore.getBsessionid(users_id => {
      this.users_id = users_id;
      this.getList();
    });
  },
  methods: {
    revoke(item) {
      this.isLoading = true;
      lower_twohand_goods({ id: item }, (res, flag) => {
        this.isLoading = false;
        if (flag) {
          if (res.code == 200) {
            this.getList();
          } else {
            this.toast(res.message);
          }
        }
      });
    },
    getList() {
      let that = this;
      that.isLoading = true;
      get_goods_list(
        { users_id: that.users_id, type: 2, status: "" },
        (res, flag) => {
          that.isLoading = false;
          if (flag) {
            if (res.code == 200) {
              if (that.page == 1) {
                that.orderList = res.data.list;
              } else {
                that.orderList = that.orderList.concat(res.data.list);
              }
            }
          }
        }
      );
    }
  }
};
</script>
<style lang="less" scoped>
@import "../style/sell/sellList.less";
</style>